<template>
  <div>
    <form>
      <el-card>
        <!--上方搜索栏-->
        <div class="demo-input-size">

        </div>
        <!--表格区-->
        <el-table :data="queryList" border stripe>
          <el-table-column type="index" label="序号"></el-table-column>
          <el-table-column label="设备号" prop="no"></el-table-column>
          <el-table-column label="设备名" prop="name"></el-table-column>
          <el-table-column label="购入时间" prop="buyTime"></el-table-column>
          <el-table-column label="购入花费(元)" prop="cost"></el-table-column>
          <el-table-column label="总数">
            <template slot-scope="scope">
              <el-input v-model="scope.row.total" type='number'
                        min='0'
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="可租赁数">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remain" type='number'
                        min='0'></el-input>
            </template>
          </el-table-column>
          <el-table-column label="租赁花费(元)">
            <template slot-scope="scope">
              <el-input v-model="scope.row.rentCost" type='number' min='0'></el-input>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="success" round size="mini" @click="update(scope.row)">更新</el-button>
              <el-button type="danger" round size="mini" @click="remove(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--  分页区-->

      </el-card>
    </form>
  </div>
</template>

<script>

export default {
  name: "Equipment",
  mounted() {
    this.query();
  },
  data() {
    return {
      queryInfo: {},
      queryList: [],
      pageSize: 7,

    }
  },
  methods: {
    query() {
      this.$http.get("/admin/eq").then(res => {
        if (res.data.code === 200) {
          this.queryList = res.data.data;
        } else {
          this.$message.error(res.data.msg)
        }
      }).catch(err => {
        this.$message.error("数据加载失败")
      })
    },
    update(row) {
      row.total = Math.round(row.total);
      row.remain = Math.round(row.remain);
      // noinspection JSCheckFunctionSignatures
      row.rentCost = parseFloat(parseFloat(row.rentCost).toFixed(2));
      this.$http.post("/admin/equpdate", row).then(res => {
        if (res.data.code === 200) {
          this.$message.success("更新成功")
        } else {
          this.$message.error(res.data.msg)
          this.query();
        }
      }).catch(err => {
        console.log(err);
      })

    },
    remove(row) {
      this.$http.get("/admin/equpdate", {
        params:{
         no: row.no
        }
      }).then(res => {
        if (res.data.code === 200) {
          this.$message.success("删除成功")
          this.query();
        } else {
          this.$message.error(res.data.msg)
        }
      }).catch(err => {
        console.log(err);
      })

    }
  }
}
</script>

<style scoped>

</style>
